<?php

$ROLE = $this->user->get_id_profile_type();

$twig->context_merge(GetTwigProfile($this->user));

$twig->context['commands'] = [
    Commands::COMMAND_HOME(),
    // Commands::COMMAND_BACK('main'),
    Commands::COMMAND_LOGOUT(),
];

$twig->context['tabs'] = [];

$tab_selected = 0;

if ($ROLE == PROFILE_SUPER_ADMINISTRATEUR) {
    if (isset($_GET['account'])) {
        $twig->context['tab_selected'] = $tab_selected;
    }
    $twig->context['tabs'][] = [
        'name' => BASE_WWW . (isset($_GET['account']) ? 'accounts/' . $_GET['account'] : 'accounts/list'),
        'text' => Strings::LABEL_0016,
    ];
    $tab_selected+=1;
}
if (in_array($ROLE, [ PROFILE_SUPER_ADMINISTRATEUR, PROFILE_ADMINISTRATEUR])) {
    if (isset($_GET['node'])) {
        $twig->context['tab_selected'] = $tab_selected;
    } elseif (isset($_GET['profile'])) {
        $twig->context['tab_selected'] = $tab_selected + 1;
    }
    $twig->context['tabs'][] = [
        'name' => BASE_WWW . (isset($_GET['node']) ? 'nodes/' . $_GET['node'] : 'nodes/list'),
        'text' => Strings::LABEL_0054,
    ];
    $twig->context['tabs'][] = [
        'name' => BASE_WWW . (isset($_GET['profile']) ? 'profiles/' . $_GET['profile'] : 'profiles/list'),
        'text' => Strings::LABEL_0017,
    ];
//    $twig->context['tabs'][] = [
//        'name' => BASE_WWW . 'courses/list',
//        'text' => Strings::LABEL_0223,
//    ];
    $tab_selected+=2;
}
if (in_array($ROLE, [ PROFILE_SUPER_ADMINISTRATEUR, PROFILE_ADMINISTRATEUR, PROFILE_EXPERT_RH, PROFILE_MANAGER, PROFILE_COLLABORATEUR])) {
    if (isset($_GET['user'])) {
        $twig->context['tab_selected'] = $tab_selected;
    }
    $twig->context['tabs'][] = [
        'name' => BASE_WWW . (isset($_GET['user']) ? 'users/' . $_GET['user'] : 'users/index'),
        'text' => Strings::LABEL_0041,
    ];

    if ($model) { /* = bulk report */
        $twig->context['tab_selected'] = $tab_selected; /* = last tab (users) */
        $twig->context['accordion_selected'] = 2; /* = bulk pane */
    }
}

$twig->display('main');
